package com.login.presenter;

import android.os.Handler;
import android.os.Looper;

import com.login.model.IUser;
import com.login.model.UserModel;
import com.login.view.ILoginView;

public class LoginPresenterCompl implements ILoginPresenter {
	ILoginView iLoginView;
	IUser iUser;
	Handler handler;


	public LoginPresenterCompl(ILoginView iLoginView) {
		this.iLoginView = iLoginView;
		handler = new Handler(Looper.getMainLooper());
		initUser();
		
	}

	private void initUser() {
		iUser = new UserModel("zhangxg", "mvp");
	}

	@Override
	public void clear() {
		iLoginView.onClearText();
	}

	@Override
	public void doLogin(String name, String passwd) {
		//一系列登录逻辑处理
		Boolean isLoginSuccess = true;
		final int code = iUser.checkUserValidity(name, passwd);
		if(code != 0){
			isLoginSuccess = false;
		}
		final Boolean result = isLoginSuccess;
		handler.post(new Runnable() {
			
			@Override
			public void run() {
				iLoginView.onLoginResult(result, code);
			}
		});
	}

	@Override
	public void setProgressBarVisibility(int visibility) {
		iLoginView.onSetProgressBarVisibility(visibility);
	}

}
